<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
import Edit from "./../edit/index";
export default {
    mixins: [
        Vue.prototype.$vFN.Mixins.Base,
        Vue.prototype.$vFN.Mixins.Page,
        Vue.prototype.$vFN.Mixins.Table,
    ],
    components: {
        SelectDataGoods: async () =>
            Vue.extend(await Vue.prototype.$vFN.Components.Base.SelectDataGoods()),
    },
    data() {
        return {
            appWindow: window,
            // 页面接口地址
            apiUrl: {
                list: "plugin/supply/SupplyGoods/getLists",
                delete: "",
            },
            // 表格查询数据
            mixinTable_tableSearchData: {
                // title: "",
            },
            // 列表高级查询参数
            mixinTable_tableSearchSenior: {
                // 商品名称
                title: {
                    type: Number,
                    value: "",
                    default: 0,
                },
                // 
                is_selected: {
                    type: Number,
                    value: 0,
                    default: 0,
                },
                // 来源1云仓2京东6阿里巴巴7天猫
                source: {
                    type: Number,
                    value: 0,
                    default: 0,
                },
                // 是否包邮
                is_free_shipping: {
                    type: Number,
                    value: -1,
                    default: 0,
                },
                // 区间筛选类型
                range_type: {
                    type: String,
                    value: "",
                    default: "",
                },
                range_from: {
                    type: String,
                    value: "",
                    default: 0,
                },
                range_to: {
                    type: String,
                    value: "",
                    default: 0,
                },

                category_id: {
                    type: Object,
                    value: "",
                    default: "",
                },

                // 排序
                sort: {
                    type: String,
                    value: "asc",
                    default: "",
                },

            },
            // 表格数据
            tableData: [],
            // 表格数据删除展示结构
            tableDeleteConfig: {
                columns: [
                    {
                        label: "分类名称",
                        prop: "name",
                        type: "",
                    },
                    {
                        label: "绑定门店数",
                        prop: "count",
                        type: "",
                    },
                ],
            },
            // 分类列表1、2、3级
            option1: [],
            option2: [],
            option3: [],

            // 
            categoryId1: "",
            categoryId2: "",
            categoryId3: "",

            checkList: [],

            type: "created_time",
        };
    },
    
    methods: {
        async getClass() {
            // 一级分类获取数据。(正常请求，不用传参)
            let res1 = await this.$vFN.Http.post({
                url: "plugin/supply/supplyCategory/getCategory",
            }, window);
            this.option1 = res1.data;
        },
        async getClass2() {
            this.categoryId2 = "";
            this.categoryId3 = "";
            // 二级分类获取数据。(要传参，传一级分类选择的参数id)
            let res2 = await this.$vFN.Http.post({
                url: "plugin/supply/supplyCategory/getCategory",
                data: {
                    parent_id: this.categoryId1,
                }
            }, window);
            this.option2 = res2.data;
        },
        async getClass3() {
            this.categoryId3 = "";
            // 三级分类获取数据。(要传参，传二级分类选择的参数id)
            let res3 = await this.$vFN.Http.post({
                url: "plugin/supply/supplyCategory/getCategory",
                data: {
                    parent_id: this.categoryId2,
                }
            }, window);
            this.option3 = res3.data;
        },
        // 一级分类清空，二级、三级分类也清空
        myClear() {
            this.categoryId2 = "";
            this.categoryId3 = "";
        },
        // 二级分类清空，、三级分类也清空
        myClear2() {
            this.categoryId3 = "";
        },

        // 选完分类搜索刷新
        myChange() {
            // 一级分类为"",category_id传空
            if(this.categoryId1 == "") {
                this.categoryId2 == "";
                this.categoryId3 == "";
                this.mixinTable_tableSearchSenior.category_id.value = ""
            }

            if(this.categoryId1 != "" && this.categoryId2 != "" && this.categoryId3 != "") {
                this.mixinTable_tableSearchSenior.category_id.value = this.categoryId3;
            }
            if(this.categoryId1 != "" && this.categoryId2 != "" && this.categoryId3 == ""){
                this.mixinTable_tableSearchSenior.category_id.value = this.categoryId2;
            }
            if(this.categoryId1 != "" && this.categoryId2 == "" && this.categoryId3 == ""){
                this.mixinTable_tableSearchSenior.category_id.value = this.categoryId1;
            }
            this.mixinTable_searchData();
        },



        clearCheckList() {
            this.checkList = []
        },
        // 打开添加/修改
        editBoxOpen(params_) {
            Edit.init({
                // mixinEdit_parent: this,
                // mixinEdit_editType: params_.type,
                checkList: this.mixinTable_selectTableData,
                onSuccess:() => {
                    this.mixinTable_refreshData();
                }
            });
        },
        // 初始化
        async init() {
            this.getClass()
            this.mixinTable_refreshData();
        },
    },
    mounted() {
        this.init();
    },
    activated() {},
};
</script>